<template>
  <div id="dz_history" class="page in" data-title>
    <div class="container">
      <header>
        <a @click="$utils.gotopage('','back')" class="pa back"></a>
        
      </header>

      <div class="history-wrap">
        <div class="search-wrap flex-wrap-start">
          <div>
            <input type="text" ref='search' />
          </div>
          <span @click="nfsearch">搜索</span>
        </div>

        <div class="history-ul pa">
          <div class="history-li flex-wrap-start" v-for="(item, index) in items" :key="index" :data-ibcustom="item.ibcustom" :data-customer_id="item.customer_id"   @click="viewpage">
            <block v-if="item.ibcustom==1">
              <img  src="/static/img/addPeer.png" alt />
              <div :data-ibcustom="item.ibcustom">
                <span>{{item.mac_type}}</span>                
                <span>{{item.at_time}}</span>                 
              </div>
            </block>
            <block v-else>              
              <img :src="item.mac_img" alt />
              <div>
                <span>{{item.mac_type}}</span>
                <span>{{item.company}}</span>
                <span>{{item.at_time}}</span>
              </div>
            </block>

          </div>
        </div>
        
      </div>
    </div>
  </div>
</template>

<script>
var mySelf;
export default {
  data() {
    return { items:[] };
  },
  beforeCreate() {
			this.$myUtils.isLoginGotoPage();	
		},
  mounted() {
    mySelf = this;
    this.init();
  },
  methods: {
    init: function () {
      	uni.showToast({
							title: '正在加载数据',
							icon:'loading',
							duration:1000
                        });
        
        this.$myUtils.myRequest({
          url: '/Customer/historyList?user_id='+mySelf.$myUtils.getStorage('userId') 
          
				}).then(res => {	
       	 
					mySelf.items = res.data.req; 

        })	
    },

    nfsearch:function() {
                
        let _search =  mySelf.$refs.search.valueSync;
        if (_search) {
          uni.showToast({
							title: '提示：搜索只能过滤非自定义项',
							icon:'loading',
							duration:1000
                        });
        }
        this.$myUtils.myRequest({
          url: '/Customer/historyList',
          data:{'mac_type':  _search,'user_id':mySelf.$myUtils.getStorage('userId')},
          method:'POST'
				}).then(res => {	       	 
          mySelf.items = res.data.req; 
          if (!mySelf.items) {
              uni.showToast({
							title: '未找到符合条件的数据',
							icon:'info',
							duration:1000
                        });
              mySelf.items = res.data.data; 
          
          }

        })	

    },
    viewpage:function(ev) {
     
      let ibcustom = ev.currentTarget.dataset.ibcustom;
       if (ibcustom==1) {
          let customer_id = ev.currentTarget.dataset.customer_id;
          let url = "/pages/history/custom?customer_id="+ customer_id;
          this.$myUtils.gotopage(url,'navigateTo');
      } else {
        let customer_id = ev.currentTarget.dataset.customer_id;
        let url = "/pages/history/configinfo?customer_id="+ customer_id;
        this.$myUtils.gotopage(url,'navigateTo');
      }

    }
     
  },
};
</script>
